/*

测试glog

*/

#include <codecvt>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <locale>
#include "GLogHelper.h"
#include "func.h"

std::string GenerateLogFileName() {
    // 获取当前时间
    std::time_t now = std::time(nullptr);
    std::tm* now_tm = std::localtime(&now);

    // 生成基于日期的日志文件名
    std::ostringstream oss;
    oss << (now_tm->tm_year + 1900) << "-" << std::setfill('0') << std::setw(2)
        << (now_tm->tm_mon + 1) << "-" << std::setfill('0') << std::setw(2) << now_tm->tm_mday
        << ".log";

    return oss.str();
}

// 获取exe所在的路径
// std::wstring GetExecutablePath() {
// 	wchar_t path[MAX_PATH] = { 0 };
// 	HMODULE hModule = GetModuleHandleW(NULL);

// 	if (hModule != NULL) {
// 		if (GetModuleFileNameW(hModule, path, MAX_PATH) > 0) {
// 			// 查找最后一个反斜杠的位置，它之前的就是目录
// 			std::wstring::size_type pos = std::wstring(path).find_last_of(L"\\/");
// 			return std::wstring(path).substr(0, pos);
// 		}
// 	}

// 	return std::wstring();
// }

std::string wstringTostring(const std::wstring& wideStr) {
    std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
    return converter.to_bytes(wideStr);
}

int main() {
    std::cout << "test glog\n";

    // std::wstring exePath = GetExecutablePath();
    // std::string  strLogPath = wstringTostring(exePath) + "/Log/agent_" + GenerateLogFileName();

    std::string strLogPath = "./Log/agent_" + GenerateLogFileName();

    GLogHelper& glogHelper = GLogHelper::Instance();
    glogHelper.InitLog(false, OutputType::Console, strLogPath);

    for (int i = 0; i < 50000; i++) {
        LOG_INFO << "This is a INFO message.";
        LOG_WARNING << "This is a WARNING message.";
        LOG_ERROR << "This is a ERROR message.";

        std::string str1 = "test std::string log";
        LOG_INFO << str1;

        int age = 20;
        LOG_INFO << "age = " << age;
        LOG_INFO_FMT("age = {}", 46);
        std::string str2 = "yuwei";
        LOG_INFO_FMT("my name: {1},age:{0}", 18, str2);
        sum(10, 20);
    }

    return 0;
}
